package com.ruoyi.business.component.mqconsumer;

import com.ruoyi.business.service.ILoanService;
import com.ruoyi.common.exception.BusinessException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.ruoyi.business.service.ILoanApplyService.LOAN_APPLY_TOPIC;

/**
 * 提现申请消费
 *
 * @author cyh
 * @date 2022/5/11 11:45 上午
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "${rocketmq.consumers.loanApplyConsumers}", topic = "${rocketmq.consumer-topics.loanApplyTopic}",
        messageModel = MessageModel.CLUSTERING,
        consumeMode = ConsumeMode.ORDERLY)
public class LoanApplyConsume implements RocketMQListener<String> {

    @Autowired
    private ILoanService loanService;

    @Override
    public void onMessage(String loanSerialNo) {
        log.info("提现申请队列消费开始，loanSerialNo：{}", loanSerialNo);
        try {
            loanService.rulePass(loanSerialNo);
        } catch (Exception e) {
            log.error("提现申请队列消费开始，loanSerialNo：" + loanSerialNo, e);
        }

        log.info("提现申请队列消费结束，loanSerialNo：{}", loanSerialNo);
    }

}
